home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 014 / dex / dex.y < prev    next >
Text File  |  1995-03-17  |  4KB  |  172 lines

  1. %{
  2. /************************************************************************
  3.  *                                    *
  4.  *            Copyright (c) 1982, Fred Fish            *
  5.  *                All Rights Reserved                *
  6.  *                                    *
  7.  *    This software and/or documentation is released for public    *
  8.  *    distribution for personal, non-commercial use only.        *
  9.  *    Limited rights to use, modify, and redistribute are hereby    *
  10.  *    granted for non-commercial purposes, provided that all        *
  11.  *    copyright notices remain intact and all changes are clearly    *
  12.  *    documented.  The author makes no warranty of any kind with    *
  13.  *    respect to this product and explicitly disclaims any implied    *
  14.  *    warranties of merchantability or fitness for any particular    *
  15.  *    purpose.                            *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19. %}
  20.  
  21. /*
  22.  *  FILE
  23.  *
  24.  *    dex.y   YACC grammar for documentation extraction utility
  25.  *
  26.  *  KEY WORDS
  27.  *
  28.  *    YACC specifications
  29.  *    dex grammar
  30.  *    
  31.  *  SYNOPSIS
  32.  *
  33.  *    yacc dex.y
  34.  *    mv y.tab.c dex.c
  35.  *
  36.  *  DESCRIPTION
  37.  *
  38.  *    This file contains the yacc grammar specification for the 
  39.  *    documentation extraction utility "dex".  Along with the
  40.  *    file "dex.l", which is the lex specification, this file
  41.  *    implements much of the control structure for extracting
  42.  *    documentation from program source files and compiling
  43.  *    it into a form suitable for input to the NROFF text formatter.
  44.  *
  45.  *  BUGS
  46.  *
  47.  *    Since the author is still learning parsing techniques,
  48.  *    grammar definition, etc, the grammar probably has
  49.  *    some rough spots.
  50.  *
  51.  *    Error reporting is minimal and currently processing
  52.  *    stops with the first error found in a given file.
  53.  *
  54.  *  AUTHOR
  55.  *
  56.  *    Fred Fish
  57.  *
  58.  */
  59.  
  60. %{
  61. #include <stdio.h>
  62.  
  63. #define TRUE 1
  64. #define FALSE 0
  65.  
  66. char savedtext[256];        /* Text for current line */
  67.  
  68. extern char *infile;        /* Input file name if not stdin */
  69. extern int linenum;        /* Current input file line number */
  70. extern FILE *infp;        /* Input stream */
  71. extern int debug;        /* Debug variable */
  72.  
  73. %}
  74.  
  75. %token BSTART TEXT JUNK HSTART FSTART UFSTART NEWLINE
  76.  
  77. %%
  78.  
  79. file    :    line
  80.             {if(debug){printf("yyparse: file\n");}}
  81.     |    file line
  82.             {if(debug){printf("yyparse: file\n");}}
  83.     |    /* empty */
  84.             {if(debug){printf("yyparse: file\n");}}
  85.     ;
  86.  
  87. line    :    junk
  88.             {
  89.                 if(debug){printf("yyparse: line\n");}
  90.                 reset_section();
  91.             }
  92.     |    id_line
  93.             {if(debug){printf("yyparse: line\n");}}
  94.     |    blank_line
  95.             {if(debug){printf("yyparse: line\n");}}
  96.     |    filled_line
  97.             {if(debug){printf("yyparse: line\n");}}
  98.     |    unfilled_line
  99.             {if(debug){printf("yyparse: line\n");}}
  100.     ;
  101.  
  102. junk    :    JUNK
  103.             {if(debug){printf("yyparse: junk\n");}}
  104.     |    newline
  105.             {if(debug){printf("yyparse: junk\n");}}
  106.     |    junk newline
  107.             {if(debug){printf("yyparse: junk\n");}}
  108.     ;
  109.  
  110. id_line    :    HSTART text newline
  111.             {
  112.                 {if(debug){printf("yyparse: id_line\n");}}
  113.                 set_section(savedtext);
  114.             }
  115.     ;
  116.  
  117.  
  118. blank_line :    BSTART newline
  119.             {
  120.                 {if(debug){printf("yyparse: blank_line\n");}}
  121.                 emit_bline();
  122.             }
  123.     ;
  124.  
  125. filled_line :    FSTART text newline
  126.             {
  127.                 {if(debug){printf("yyparse: filled_line\n");}}
  128.                 emit_filled(savedtext);
  129.             }
  130.     ;
  131.  
  132. unfilled_line :    UFSTART text newline
  133.             {
  134.                 {if(debug){printf("yyparse: unfilled_line\n");}}
  135.                 emit_unfilled(savedtext);
  136.             }
  137.     ;
  138.  
  139.  
  140. newline :    NEWLINE
  141.             {
  142.                 {if(debug){printf("yyparse: newline\n");}}
  143.                 linenum++;
  144.             }
  145.     ;
  146.  
  147. text    :    TEXT
  148.             {
  149.                 {if(debug){printf("yyparse: text\n");}}
  150.                 strcpy(savedtext,yytext);
  151.             }
  152.     ;
  153.  
  154. %%
  155.  
  156. #include "dex.lo"        /* LEX output; renamed from lex.yy.c */
  157.  
  158. yywrap ()            /* Thought this was in library */
  159. {
  160.     return(1);
  161. }
  162.  
  163. yyerror(sp)
  164. char *sp;
  165. {
  166.     fprintf(stderr,"%s: ",infile);        /* What file */
  167.     fprintf(stderr,"line %d: ",linenum);    /* Where in file */
  168.     fprintf(stderr,"%s: ",sp);            /* What was wrong */
  169.     fprintf(stderr,"%s\n",yytext);        /* What it choked on */
  170. }
  171.  
  172.